
Imports System.Data
Imports System.Data.SqlClient


Namespace Ventas
Public Class Descuentos

public Function Listar(DescuentoId as integer) as Entity.Ventas.Descuentos

Dim strNameProcedure as string = "up_Ven_Descuentos_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Ventas.Descuentos
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@DescuentoId", SqlDbType.Int)).Value =DescuentoId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Ventas.Descuentos
With objEnt
		.DescuentoId = sqlReader("DescuentoId").ToString
		.Nombre = sqlReader("Nombre").ToString
		.Descripcion = sqlReader("Descripcion").ToString
		.Estado = sqlReader("Estado").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		DescuentoId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Estado as Integer) _
as  Entity.Ventas.DescuentosCol

Dim strNameProcedure as string = "up_Ven_Descuentos_listar"
dim objCol as   entity.Ventas.DescuentosCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 cmd.Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,50)).Value =Nombre
 cmd.Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,150)).Value =Descripcion
 cmd.Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iDescuentoId as integer = dr.GetOrdinal("DescuentoId")
		dim iNombre as integer = dr.GetOrdinal("Nombre")
		dim iDescripcion as integer = dr.GetOrdinal("Descripcion")
		dim iEstado as integer = dr.GetOrdinal("Estado")
		dim i_usu_Cre as integer = dr.GetOrdinal("_usu_Cre")
		dim i_fec_Cre as integer = dr.GetOrdinal("_fec_Cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_fec_mod as integer = dr.GetOrdinal("_fec_mod")
		dim i_flg_eli as integer = dr.GetOrdinal("_flg_eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Ventas.DescuentosCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Ventas.Descuentos
dr.GetValues(values)

		objEnt.DescuentoId = values(iDescuentoId)
		objEnt.Nombre = values(iNombre)
		objEnt.Descripcion = values(iDescripcion)
		objEnt.Estado = values(iEstado)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		DescuentoId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Estado as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_Descuentos_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 .Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,50)).Value =Nombre
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,150)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		DescuentoId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Estado as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Ven_Descuentos_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@DescuentoId",SqlDbType.INT)).Value =DescuentoId
 .Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,50)).Value =Nombre
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,150)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@Estado",SqlDbType.SMALLINT)).Value =Estado
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, DescuentoId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Ven_Descuentos_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@DescuentoId", SqlDbType.Int)).Value =DescuentoId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

